<?php
class common_run {
	/**
	 * 构造函数
	 */
	public function __construct() {
		//全局常量
		define('ROOT', dirname(dirname(__FILE__)));
		define('ACCESS', 1);
		
		//加载文件
		require ROOT.'/config/config.php';
		require ROOT.'/common/functions.php';
		require ROOT.'/common/functions_app.php';
		
		//设置时区
		ini_set('date.timezone', 'Asia/Shanghai');
		
		//接收参数
		$module = $_GET['m'];
		$action = $_GET['a'];
		$module == '' && $module = 'index';
		$action == '' && $action = 'index';
		
		//调用controller
		$controller_class = 'controller_'.$module;
		$controller_action = 'action_'.$action;
		$controller = new $controller_class;
		if(method_exists($controller, $controller_action)) {
			$controller->$controller_action();
		} else {
			throw new common_exception('Action Not Found');
		}
		
		//调用view
		$template_path = ROOT.'/view/'.$module.'/'.$action.'.php';
		if(file_exists($template_path)) {
			$controller->display($template_path);
		}
	}
	
}
?>